#include "InviteNotify.h"

json InviteNotify::serialize() const {
    try{
    json j;
    j["type"]=type;
    j["sender_id"]=sender_id;
    j["receiver_id"]=receiver_id;
    j["chat_room_id"]=chat_room_id;
    j["content"]=content;
    j["time"]=time;
    return j;
    }catch(exception& e){
        syslog(LOG_ERR, "InviteNotify serialize error:%s", e.what());
        #ifdef DEBUG
        PRINT_ERRNO_AND_STRERROR(errno, "InviteNotify serialize error:%s", e.what());
        #endif
        throw e;
    }
}

void InviteNotify::unserialize(const json& j) {
    try{
        this->type=j["type"].get<NotifyType>();
        this->sender_id=j["sender_id"].get<int>();
        this->receiver_id=j["receiver_id"].get<int>();
        this->chat_room_id=j["chat_room_id"].get<string>();
        this->content=j["content"].get<string>();
        this->time=j["time"].get<string>();
    }catch(exception& e){
        syslog(LOG_ERR, "InviteNotify unserialize error:%s", e.what());

        #ifdef DEBUG
        PRINT_ERRNO_AND_STRERROR(errno, "InviteNotify unserialize error:%s", e.what());
        #endif

        throw e;
    }
}

InviteNotify::InviteNotify(const int& sender_id, const int& receiver_id, const string& chat_room_id, const string& content, const string& time) {
    this->type = INVITE_NOTIFY;
    this->sender_id = sender_id;
    this->receiver_id = receiver_id;
    this->chat_room_id = chat_room_id;
    this->content = content;
    this->time = time;
}

NotifyType InviteNotify::get_notify_type() const {
    return INVITE_NOTIFY;
}

InviteNotify::InviteNotify(json msg_notify_json) {
    unserialize(msg_notify_json);
}


